package main

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

func test() {
	db, err := sql.Open("mysql", "root:luyis520@/test?charset=utf8")
	//checkErr(err)
	fmt.Println(err)
	// ____________insert
	// stmt, err := db.Prepare("INSERT cloth SET name=?,color=?")
	// fmt.Print(err)
	// res, err := stmt.Exec("wwww", "www")
	// fmt.Print(res)
	// ______________update
	// stmt, err := db.Prepare("update cloth set name=? where id=?")
	// fmt.Print(err)

	// res, err := stmt.Exec("qqq", 1)
	// fmt.Print(res)
	//affect, err := res.RowsAffected()
	//checkErr(err)
	//fmt.Println(affect)
	// ________query
	rows, err := db.Query("SELECT * FROM cloth")
	//checkErr(err)

	//fmt.Print(rows)
	for rows.Next() {
		var id int
		var name string
		var color string
		err = rows.Scan(&id, &name, &color)
		//checkErr(err)
		fmt.Println(id)
		fmt.Println(name)
		fmt.Println(color)
	}

	// ___________delete
	//stmt, err = db.Prepare("delete from cloth where id=?")
	//checkErr(err)

	//res, err = stmt.Exec(1)
	//checkErr(err)

	// query
	// 	rows, err = db.Query("SELECT * FROM cloth")
	// 	checkErr(err)

	// 	for rows.Next() {
	// 		var uid int
	// 		var username string

	// 		err = rows.Scan(&uid, &username)
	// 		checkErr(err)
	// 		fmt.Println(uid)
	// 		fmt.Println(username)
	// 	}

	db.Close()

	// }

	// func checkErr(err error) {
	// 	if err != nil {
	// 		panic(err)
	// 	}
}
